package wql.aaa.service.impl;

import com.aaa.entity.TbZoneBusiness;
import com.aaa.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wql.aaa.dao.ZoneBussinessDao;
import wql.aaa.service.ZoneBusinessService;
import wql.aaa.service.ZoneService;
import wql.aaa.vo.BusinessFromData;
import wql.aaa.vo.SearchFormData;
import wql.aaa.vo.SearchFormsData;

import java.util.Date;
import java.util.List;
import java.util.stream.StreamSupport;

/**
 * @author wql
 * @version 1.0
 * @date 2023/2/27 20:44
 */
@Service
public class ZoneBusinessServiceImpl implements ZoneBusinessService {

    @Autowired
    private ZoneBussinessDao zoneBussinessDao;
    @Override
    public Result queryAll(Integer currentPage, Integer pageSize, SearchFormsData searchFormsData) {
        PageHelper.startPage(currentPage,pageSize);

        List<TbZoneBusiness> byZoneId = zoneBussinessDao.findByZoneId(searchFormsData);

        PageInfo<TbZoneBusiness> info = new PageInfo<>(byZoneId);

        return new Result(2000,"查询成功",info);
    }

    @Override
    public Result updateIsDisabled(String id, Integer isDisable) {
        zoneBussinessDao.change(id, isDisable);
        return new Result(2000,"修改成功");

    }

    @Override
    public Result deleteById(String id) {
        zoneBussinessDao.deleteByZBId(id);
        return new Result(2000,"删除成功");
    }

    @Override
    public Result changeSort(String id, Integer sort) {
        zoneBussinessDao.changeSort(id,sort);

        return new Result(2000,"修改成功");
    }

    @Override
    public Result addBusiness(Integer currentPage, Integer pageSize, BusinessFromData businessFromData) {
        PageHelper.startPage(currentPage,pageSize);
        List<TbZoneBusiness> tbZoneBusinesses = zoneBussinessDao.selectBusiness(businessFromData);
        PageInfo<TbZoneBusiness> info = new PageInfo<>(tbZoneBusinesses);
        return new Result(2000,"查询成功",info);
    }

    @Override
    public Result addBusinessDetail(String id ,String zoneId) {
        TbZoneBusiness tbZoneBusiness = new TbZoneBusiness();
        tbZoneBusiness.setZoneId(zoneId);
        tbZoneBusiness.setBid(id);
        Date date = new Date();
        tbZoneBusiness.setGmtCreate(date);
        tbZoneBusiness.setGmtModified(date);
        tbZoneBusiness.setIsDeleted(0);
        tbZoneBusiness.setIsDisable(0);
        tbZoneBusiness.setSort(2);
        tbZoneBusiness.setPutaway(1);
        zoneBussinessDao.insert(tbZoneBusiness);
        return new Result(2000,"添加成功");
    }

    @Override
    public Result changePutAway(String id) {

        zoneBussinessDao.changePutAway(id);

        return new Result(2000, "上架成功");
    }
}
